#include<iostream>
#include<unistd.h>
#include<cstring>
int main(){
    int fds[2];
    int pid=-1;
    if(pipe(fds)==-1){
        perror("pipe:");
        return 0;
    }
    pid=fork();
    if(pid==-1){
        perror("fork:");
        return 0;
    }
    else if(pid==0){
        
        close(fds[1]);
        char buf[100];
        for(int i=0;i<10;i++){
            read(fds[0],buf,100);
            std::cout<<buf<<std::endl;
        }
    }
    else{
        
        close(fds[0]);
        const char* s="hehehe";
        for(int i=0;i<10;i++){
            write(fds[1],s,strlen(s));
            sleep(1);
        }
    }
    return 0;
}
